<?php
    require '../config.php';
    
    $db=  mysql_connect(MYSQL_HOST, MYSQL_USER,MYSQL_PASSWORD) or die("Khong the ket noi thoi server");
    mysql_select_db(MYSQL_DB,$db) or (mysql_error($db));
    //tao bang nguoi dung
    $query='CREATE TABLE IF NOT EXISTS site_user(
        user_id     INTEGER    NOT NULL AUTO_INCREMENT,
        username    VARCHAR(20) NOT NULL,
        password    CHAR(41)    NOT NULL,
        
        PRIMARY KEY (user_id)
        )
        ENGINE=MyISAM';
    mysql_query($query,$db) or die(mysql_error($db));
    //thong tin nguoi dung
    $query='CREATE TABLE IF NOT EXISTS site_user_info(
            user_id     INTEGER     NOT NULL,
            full_name  VARCHAR(50) NOT NULL,
            address   VARCHAR(256) NOT NULL,
            email       VARCHAR(50) NOT NULL,
            sdt        VARCHAR(20),
            state       CHAR(2),
            hobbies     VARCHAR(255),
            
            FOREIGN KEY (user_id) REFERENCES site_user(user_id)
    )
    ENGINE=MyISAM';
    mysql_query($query,$db) or die(mysql_error($db));
    // them du lieu vao tai khoan
    $query='INSERT IGNORE INTO site_user
        (user_id, username, password)
        VALUES
        (1,"admin",PASSWORD("admin")),
        (2,"user",PASSWORD("user"))';
    mysql_query($query,$db) or die(mysql_error($db));
    
    //them du lieu vao bang thong tin nguoi dung
    $query='INSERT IGNORE INTO site_user_info
        (user_id, full_name, address, email, sdt, state, hobbies)
        VALUES
        (1,"congvien","tran nhan tong","tinhanhk32@gmail.com",NULL, NULL, NULL),
        (2,"kaka","bui thi xuan","congvienit@gmail.com",NULL, NULL, NULL)';
    mysql_query($query,$db) or die(mysql_error($db));
    echo "Thanh Cong !";
?>
